<?php
/**
 * Created by PhpStorm.
 * User: win7
 * Date: 2018/5/14 0014
 * Time: 14:50
 */

namespace Wx\Controller;
use Think\Controller;

class StoreOrderDetailController extends Controller
{
    public function Index(){
        $c_id = I('cid') ?I('get.cid'):I('post.cid');//获取拼团商品副本表id
        $o_id = I('oid') ?I('get.oid'):I('post.oid');//获取拼团订单表id

        $spellgroup = M("shop_spellgroup");
        $spellgroup_copy = M("shop_spellgroup_copy");
        $spellgroup_order = M("shop_spellgroup_order");

        if($c_id){
            $spellgroup_copy_info = $spellgroup_copy->where("id = {$c_id} AND orsuccess = 1")->find();//获取商品副本表信息
            $order_all = $spellgroup_order->where("c_id = {$c_id}")->select();//获取该副本所有订单
            foreach($order_all as $k => $v){
                $order_all[$k]['member'] = getMember($v['u_id'],'avatar,nickname,hometown');
            }
        }
        if($o_id){
            $spellgroup_order_info = $spellgroup_order->where("id = {$o_id}")->find();//获取订单信息
            $spellgroup_copy_info = $spellgroup_copy->where("id = {$spellgroup_order_info['c_id']} AND orsuccess = 1")->find();//获取商品副本表信息
            $sum_order = $spellgroup_order->where("c_id = {$spellgroup_copy_info['id']} AND state = 2")->field("*,Sum(num) AS sum")->find();//获取该副本所有已核销订单份数
            $spellgroup_copy_info['sum'] = $sum_order['sum'] > 0?$sum_order['sum']:0;//已核销订单份数

            $order_all = $spellgroup_order->where("c_id = {$spellgroup_copy_info['id']}")->select();//获取该副本所有已核销订单份数
            foreach($order_all as $k => $v){
                $order_all[$k]['member'] = getMember($v['u_id'],'avatar,nickname,hometown');
            }
        }
        $spellgroup_info  = $spellgroup->where("id = {$spellgroup_copy_info['sg_id']}")->find();
        $this->assign('group',$spellgroup_info);
        $this->assign('copy',$spellgroup_copy_info);
        $this->assign('myorder',$spellgroup_order_info);
        $this->assign('member',$order_all);
        $this->display("orderdetail-sj02");
    }//end fun index()
}//end class